Description
For layouts, specify a TypeCode for a document type. For reports, always specify RCRI. You can only upload an .rpt file; you cannot upload a .b1p file.
ReportLayoutsService oLayoutService = (ReportLayoutsService)oCompany.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService); ReportLayout oReport = (ReportLayout)oLayoutService.GetDataInterface(ReportLayoutsServiceDataInterfaces.rlsdiReportLayout); //Initialize critical properties // // Use TypeCode "RCRI" to specify a Crystal Report. // Use other TypeCode to specify a layout for a document type. // List of TypeCode types are in table RTYP. oReport.Name = "MyReportName"; oReport.TypeCode = "RCRI"; oReport.Author = oCompany.UserName; oReport.Category = ReportLayoutCategoryEnum.rlcCrystal; string newReportCode; try { // Add new object ReportLayoutParams oNewReportParams = oLayoutService.AddReportLayout(oReport); // Get code of the added ReportLayout object newReportCode = oNewReportParams.LayoutCode; } catch (System.Exception err) { string errMessage = err.Message; return; } // Wpload .rpt file using SetBlob interface string rptFilePath = @"C:\MyReport.rpt"; CompanyService oCompanyService = oCompany.GetCompanyService(); // Specify the table and field to update BlobParams oBlobParams = (BlobParams)oCompanyService.GetDataInterface(SAPbobsCOM.CompanyServiceDataInterfaces.csdiBlobParams); oBlobParams.Table = "RDOC"; oBlobParams.Field = "Template"; // Specify the record whose blob field is to be set BlobTableKeySegment oKeySegment = oBlobParams.BlobTableKeySegments.Add(); oKeySegment.Name = "DocCode"; oKeySegment.Value = newReportCode; Blob oBlob = (Blob)oCompanyService.GetDataInterface(CompanyServiceDataInterfaces.csdiBlob); // Put the rpt file into buffer FileStream oFile = new FileStream(rptFilePath, System.IO.FileMode.Open); int fileSize = (int)oFile.Length; byte[] buf = new byte[fileSize]; oFile.Read(buf, 0, fileSize); oFile.Close(); // Convert memory buffer to Base64 string oBlob.Content = Convert.ToBase64String(buf, 0, fileSize); try { //Upload Blob to database oCompanyService.SetBlob(oBlobParams, oBlob); } catch (System.Exception ex) { string errmsg = ex.Message; } |